const util = require('../utils/util.js');
const api = require('../config/api.js');

function goTimChat(doctId, registerSource = 0, isSimple = false) {
  console.log("--------goTimChat-----------");
  let that = this;
  wx.showLoading({
    title: '加载中...',
  })
  util.request(api.timIdChat, {
    doctId: doctId, // that.data.detailInfo.doctId,
    registerSource: registerSource,
    isSimple: isSimple,
  }).then(res => {
    wx.hideLoading();
    if (res.errno == 0) {
      let data = res.data;
      if (data.isGroup) {
        wx.navigateTo({
          url: `/pagesBusiness/pages/messageNav/index?conversationID=GROUP${data.timId}`,
        })
      } else {
        wx.navigateTo({
          url: `/pagesBusiness/pages/messageNav/index?conversationID=C2C${data.timId}`,
        })
      }

    }

  }).catch(err => {
    wx.hideLoading();
  })
}


module.exports = {
  goTimChat: goTimChat,
}